package com.zxc;

import com.zxc.model.ShoppingCart;
import com.zxc.enums.Fruit;
import com.zxc.service.SupermarketService;

/**
 * 1.策略模式：PriceCalculator 接口及其实现类，可以灵活切换不同的价格计算策略
 * 2.装饰器模式：StrawberryDiscountDecorator 和 FullReductionDecorator 可以动态地给基础价格计算添加功能
 * 3.工厂模式：CalculatorFactory 根据不同客户需求创建相应的计算器
 */
public class Main {
    public static void main(String[] args) {
        SupermarketService service = new SupermarketService();

        // 顾客A购买：2斤苹果，3斤草莓
        ShoppingCart cartA = new ShoppingCart();
        cartA.addFruit(Fruit.APPLE, 2);
        cartA.addFruit(Fruit.STRAWBERRY, 3);
        double totalA = service.calculateCustomerATotal(cartA.getFruits());
        System.out.println("顾客A购买总价: " + totalA + "元"); // 2*8 + 3*13 = 16 + 39 = 55元

        // 顾客B购买：2斤苹果，3斤草莓，1斤芒果
        ShoppingCart cartB = new ShoppingCart();
        cartB.addFruit(Fruit.APPLE, 2);
        cartB.addFruit(Fruit.STRAWBERRY, 3);
        cartB.addFruit(Fruit.MANGO, 1);
        double totalB = service.calculateCustomerBTotal(cartB.getFruits());
        System.out.println("顾客B购买总价: " + totalB + "元"); // 2*8 + 3*13 + 1*20 = 16 + 39 + 20 = 75元

        // 顾客C购买：2斤苹果，3斤草莓，1斤芒果（草莓8折）
        ShoppingCart cartC = new ShoppingCart();
        cartC.addFruit(Fruit.APPLE, 2);
        cartC.addFruit(Fruit.STRAWBERRY, 3);
        cartC.addFruit(Fruit.MANGO, 1);
        double totalC = service.calculateCustomerCTotal(cartC.getFruits());
        System.out.println("顾客C购买总价: " + totalC + "元"); // 2*8 + 3*13*0.8 + 1*20 = 16 + 31.2 + 20 = 67.2元

        // 顾客D购买：5斤苹果，5斤草莓，3斤芒果（草莓8折，满100减10）
        ShoppingCart cartD = new ShoppingCart();
        cartD.addFruit(Fruit.APPLE, 5);
        cartD.addFruit(Fruit.STRAWBERRY, 5);
        cartD.addFruit(Fruit.MANGO, 3);
        double totalD = service.calculateCustomerDTotal(cartD.getFruits());
        System.out.println("顾客D购买总价: " + totalD + "元"); // 5*8 + 5*13*0.8 + 3*20 = 40 + 52 + 60 = 152元 -> 152-10 = 142元
    }
}